home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 013 / bakcheck.arc / BAKCHECK.C next >
Encoding:
C/C++ Source or Header  |  1986-08-01  |  3.9 KB  |  106 lines

  1.     /*  BAKCHECK is designed to remind the PC user to back-up their fixed
  2.         disk on a regular interval.  It accepts 1 parameter, the number of
  3.         days between regular backups.  If not given
  4.         the interval defaults to 30.  The program uses a data file stored in
  5.         the root directory named BACKDATE.DAT.  The first time the program
  6.         is run, it creates the file.  Its total length is 4 bytes - the long
  7.         integer of the results of the time() function the last time a backup
  8.         was performed.  This file is updated anytime a backup is started
  9.         from this program.  Any backup executed from the command line will
  10.         not update the data file.  For compatibility with alternate backup
  11.         systems, the program executes a BAT file called BACKIT.BAT to perform
  12.         the backup.  This allows use of a tape unit or floppy system like
  13.         fastback.
  14.  
  15.         Standard usage:
  16.                               BAKCHECK 20
  17.  
  18.         This would request a backup 20 days after the last one.  The BAKCHECK
  19.         command would typically be entered in the AUTOEXEC.BAT file.
  20.  
  21.                                                                            */
  22.  
  23.     #include <process.h>
  24.     #include <stdio.h>
  25.     #include <ctype.h>
  26.     #include <conio.h>
  27.     #include <dos.h>
  28.     #include <errno.h>
  29.  
  30.     main(argc,argv)
  31.  
  32.         int   argc;
  33.         char  *argv[];
  34.         {
  35.  
  36.             int  bperiod;
  37.             int  ans;
  38.             int  count;
  39.             int  fstat;
  40.             int  sstat;
  41.  
  42.             unsigned long lbperiod;
  43.             unsigned long newdate;
  44.             unsigned long olddate;
  45.             unsigned long elapsed;
  46.  
  47.             long time();
  48.  
  49.             FILE *datefile;
  50.  
  51.  
  52.             /*  Check for parameter, set up backup interval  */
  53.  
  54.             bperiod = 0;
  55.             if (argc<1) bperiod=30 ;
  56.             else  {
  57.                   count = sscanf(argv[1],"%d",&bperiod);
  58.                   if (count==EOF || bperiod<1) bperiod=30;
  59.                   }
  60.             lbperiod = bperiod * 86400L;
  61.  
  62.  
  63.             /*  get last backup date from disk file, create file if not there */
  64.  
  65.             newdate = time();
  66.             datefile = fopen("\\BACKDATE.DAT","r");
  67.             rewind(datefile);
  68.             fstat = fread(&olddate,sizeof(long),1,datefile);
  69.             fclose(datefile);
  70.             if (fstat==NULL)
  71.                 {
  72.                 printf("BACKDATE.DAT not found, creating...\n");
  73.                 datefile = fopen("\\BACKDATE.DAT","w");
  74.                 rewind(datefile);
  75.                 fstat = fwrite(&newdate,sizeof(long),1,datefile);
  76.                 if (fstat==0) printf("\nError in writing backdate.dat.\n");
  77.                 fclose(datefile);
  78.                 exit(1);
  79.                 }
  80.             elapsed = newdate - olddate;
  81.  
  82.             /*  If too much time has elapsed, talk to user and suggest backup */
  83.  
  84.             if (elapsed>lbperiod)
  85.                 {
  86.                 cls();
  87.                 printf("The fixed disk hasn't been backed up for more than %d days.\n",bperiod);
  88.                 printf("Would you like to back it up now?  (Y|N)  \n\n");
  89.                 ans = getche();
  90.                 ans = toupper(ans);
  91.                 if (ans=='Y')         /* lets do the backup   */
  92.                     {
  93.                     datefile = fopen("\\BACKDATE.DAT","w");
  94.                     if (datefile==NULL)  printf("\nCouldn't open file.\n");
  95.                     rewind(datefile);
  96.                     fstat = fwrite(&newdate,sizeof(long),1,datefile);
  97.                     if (fstat==0) printf("\nError in writing backdate.dat.\n");
  98.                     fclose(datefile);
  99.                     sstat=system("BACKIT.BAT");
  100.                     }
  101.                 else printf("\n\nPlease backup the disk soon.\n\n\n");
  102.                 exit(0);
  103.                }
  104.     }
  105.  
  106.